package com.site.wisdom_construction.controller.publicModule;

import com.site.wisdom_construction.responseEntity.JsonResult;
import com.site.wisdom_construction.responseEntity.OneDataResult;
import com.site.wisdom_construction.responseEntity.Page;
import com.site.wisdom_construction.service.publicModule.KnowledgeTypesService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @Author daiyifei
 * @Date 2022/5/26
 * @Description
 */
@Api(tags = "公共培训课程知识类型接口")
@RestController
@RequestMapping("KnowledgeTypes")
@CrossOrigin
public class KnowledgeTypesController {
    @Autowired
    private KnowledgeTypesService knowledgeTypesService;


    @ApiOperation(value = "增加知识类型信息", notes = "测试数据:")
    @PostMapping("/insertKnowledgeTypes")
    public JsonResult insertKnowledgeTypes(@RequestBody Map map){
        JsonResult jsonResult = new JsonResult();
        int i = knowledgeTypesService.insertKnowledgeTypes(map);
        if (i==1){
            jsonResult.setCode(200);
            jsonResult.setMessage("成功录入知识类型信息!");
        }else {
            jsonResult.setCode(20006);
            jsonResult.setMessage("录入知识类型信息失败!");
        }
        return jsonResult;
    }

    @ApiOperation(value = "删除知识类型信息", notes = "测试数据:")
    @PostMapping("/deleteKnowledgeTypes")
    public JsonResult deleteKnowledgeTypes(@RequestBody Map map){
        JsonResult jsonResult = new JsonResult();
        int i = knowledgeTypesService.deleteKnowledgeTypes(map);
        if (i==1){
            jsonResult.setCode(200);
            jsonResult.setMessage("成功删除知识类型信息!");
        }else {
            jsonResult.setCode(20006);
            jsonResult.setMessage("删除知识类型信息失败!");
        }
        return jsonResult;
    }

    @ApiOperation(value = "修改知识类型信息", notes = "测试数据:")
    @PostMapping("/updateKnowledgeTypes")
    public JsonResult updateKnowledgeTypes(@RequestBody Map map){
        JsonResult jsonResult = new JsonResult();
        int i = knowledgeTypesService.updateKnowledgeTypes(map);
        if (i==1){
            jsonResult.setCode(200);
            jsonResult.setMessage("成功修改知识类型信息!");
        }else {
            jsonResult.setCode(20006);
            jsonResult.setMessage("修改知识类型信息失败!");
        }
        return jsonResult;
    }

    @ApiOperation(value = "分页模糊查询知识类型信息", notes = "测试数据:")
    @PostMapping("/findKnowledgeTypesByPage")
    public Page findKnowledgeTypesByPage(@RequestBody Map map) {
        Page page = new Page();
        page.setPageNo((Integer) map.get("pageNo"));
        page.setPageSize((Integer) map.get("pageSize"));
        page.setTotal(knowledgeTypesService.Total(map));
        page.setItems(knowledgeTypesService.findKnowledgeTypesByPage(map));
        return page;
    }

    @ApiOperation(value = "下拉框查询知识类型信息", notes = "测试数据:")
    @PostMapping("/selectKnowledgeTypes")
    public OneDataResult selectKnowledgeTypes(@RequestBody Map map) {
        OneDataResult oneDataResult = new OneDataResult();
        oneDataResult.setData(knowledgeTypesService.selectKnowledgeTypes(map));
        return oneDataResult;
    }
}
